import json

import stomp


class TaskListener(object):
    def __init__(self, host, port):
        self.conn = stomp.Connection10([(host, port)], auto_content_length=False)
        self.conn.start()
        self.conn.connect()

    def on_message(self, headers, msg):
        print("received message %s" % json.loads(msg))
        # header = json.loads(headers)
        self.conn.send(headers['reply-to'], msg)

    def on_error(self, headers, message):
        print('received an error %s' % message)